//
//  MYRequesTool.m
//  JQLive
//
//  Created by Bruce on 2020/1/4.
//  Copyright © 2020 mlqk. All rights reserved.
//

#import "MYRequesTool.h"

@implementation MYRequesTool


+ (BOOL)requestReslutDelWith:(NSDictionary *)result{
    int code = [result[@"code"] intValue];
    // 401 为登录 失效 code
    if (code == 401){
      
        //失败 授权失败请重新登录
        NSString *alterContent = @"提示";
        UIAlertController *alertController = [UIAlertController alertControllerWithTitle:alterContent message:@"账号token验证失效，请重新登录！" preferredStyle:(UIAlertControllerStyleAlert)];
        UIAlertAction *action = [UIAlertAction actionWithTitle:@"重新登录" style:(UIAlertActionStyleDefault) handler:^(UIAlertAction * _Nonnull action) {
           [JQLiveTools logout];
        }];
        UIAlertAction *cancel = [UIAlertAction actionWithTitle:@"取消" style:(UIAlertActionStyleCancel) handler:^(UIAlertAction * _Nonnull action) {
           
        }];
        [alertController addAction:cancel];
        [alertController addAction:action];
        [[UIApplication sharedApplication].keyWindow.rootViewController presentViewController:alertController animated:YES completion:nil];
        return false;
   
    }else if(code == 200){
        //成功
        return true;
    }
    /*
    else if (code == 403){// 无权限访问
        
    }else if (code == 500){// 服务内部错误
        
    }else if (code == 502){// 网关处理失败
        
    }*/
    else{
        NSString *msg = result[@"message"];
        NSLog(@"----%@",result);
        msg = msg&&msg.length>0?msg:DefultLodErrorString;
        [MYTipUtils showErrorAlertString:msg];
        return false;
    }
}
@end
